<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        #as{
            height: 3000px;
            background: red;
            width: 200px;
        }
        #ass{
            width: 800px;
            height: 80px;
            background-color: yellow;
            line-height: 80px;
            font-size: 32px;
            font-weight: 900;
            text-align: center;
            position: fixed;
            top: 0;
            left: 50%;
            margin-left: -400px;
        }
        #but{
            display: block;
            width: 80px;
            height: 80px;
            position: fixed;
            bottom: 10px;
            right: 10px;
        }
    </style>
</head>
<body>
    <div id="as"></div>
    <p id="ass">创意公告栏</p>
    <button id="but">回到顶部</button>
</body>
</html>
<script>
    var all1 = document.querySelector('#ass')
    var all2 = document.querySelector('#but')
    window.onscroll = function(){
        var all = document.documentElement.scrollTop
        console.log(all);
        if(all > 1200){
            all1.style.display = 'none'
        }else{
            all1.style.display = 'block'
        }
        if(all < 1200){
            all2.style.display = 'none'
        }else{
            all2.style.display = 'block'
        }
        all2.onclick = function(){
            // document.documentElement.scrollTop = 0
            window.scrollTo({
                top:0,
                behavior:"smooth"
            })
        }
    }
</script>